//
//  DataStream.h
//  DataPlatform
//
//  Created by Liu Dafan on 12-2-9.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#ifndef DataPlatform_DataStream_h
#define DataPlatform_DataStream_h

#include <inttypes.h>
#include <vector>
#include <string>
#include "common.h"

class DataStream
{
public:
    DataStream();
    DataStream(std::vector<int8_t>* _data);
    DataStream(size_t size);
    ~DataStream();

    void Serialize(const int8_t* data, size_t len);
    void Serialize(const std::string& data);
    void Serialize(uint32_t data);
    void Serialize(uint64_t data);
    void Serialize(const FILE_DATA& data);
    bool UnSerialize(int8_t*& data, size_t len);
    bool UnSerialize(std::string& data);
    bool UnSerialize(uint32_t& data);
    bool UnSerialize(uint64_t& data);
    bool UnSerialize(FILE_DATA& data);

    const std::vector<int8_t>& getdata();
    void reset();
    
private:
    bool            _needfree;
    std::vector<int8_t>* _data;
    size_t          _scanidx;
};

#endif
